package com.wen.controller;

import com.wen.pojo.ProductType;
import com.wen.service.ProductService;
import com.wen.service.ProductTypeService;
import com.wen.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/productCategory")
public class ProductTypeController {
    @Autowired
    private ProductTypeService productTypeService;

    @Autowired
    private ProductService productService;

    @RequestMapping("/product-category-tree")
    public Result tree(){
        List<ProductType> productTypes = productService.productTypeTree();
        return Result.ok(200,"查询成功",productTypes);
    }

    @RequestMapping("/verify-type-code")
    public Result findType(ProductType productType){
        return productTypeService.findPCode(productType);
    }
    //添加分类
    @RequestMapping("/type-add")
    public Result addType(@RequestBody ProductType productType){
        return productTypeService.addType(productType);
    }
    //删除分类
    @RequestMapping("/type-delete/{typeId}")
    public Result delType(@PathVariable Integer typeId){
        return productTypeService.delType(typeId);
    }
    //修改分类
    @RequestMapping("/type-update")
    public Result updType(@RequestBody ProductType productType){
        return productTypeService.updType(productType);
    }
}
